<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<%@ page import="com.dog.lucene.first.IndexSearch" %>
<%@ page import="com.dog.lucene.first.IndexManager" %>
<%@ page import="com.dog.domain.Crawl" %>
<%@ page import="java.util.List" %>
<%@ page import="org.wltea.analyzer.lucene.IKAnalyzer" %>
<%@ page import="org.apache.lucene.analysis.standard.StandardAnalyzer" %>
<%@ page import="org.apache.lucene.index.IndexReader" %>
<%@ page import="org.apache.lucene.queryparser.classic.QueryParser" %>
<%@ page import="org.apache.lucene.search.IndexSearcher" %>
<%@ page import="org.apache.lucene.search.Query" %>
<%@ page import="java.util.ArrayList" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title> Dog搜</title>
	<link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">  
	<script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
	<script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>

	<style type="text/css">
	
	
	.fy
{
    position: relative;
    padding: 5px;
    left: 600px;
}

	.sou
{
    position: relative;
    padding: 5px;
    left: 350px;
    top:20px;
}


<link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">  
	</style>
</head>
<body>


<form action="query2.jsp" method="GET"  >
<div class="input-group col-md-5 sou" style="margin-top:0px positon:relative">
       <input type="text" class="form-control input-lg" name="name" placeholder="" / >
            <span class="input-group-btn">
               <button class="btn btn-info btn-lg btn-search">Dog搜</button>
            </span>
 </div>
 </form>





<br/>
<br/>


<%

List <Crawl> lis=new ArrayList();


//IndexManager b=new IndexManager();
//b.createIndex();
//out.print("索引成功");


//mmp俩个分开，免得又注释了
//解决中文乱码


String test = null; 
 
try {
	String str = new String(request.getParameter("name").getBytes("ISO-8859-1"),"utf-8");
	//就是不知道为什么str不赋值给test的话会一直报错？？？这个好好的去研究一下
	//out.print(str);
	test=str;
	IndexSearch a=new IndexSearch();
	QueryParser parser = new QueryParser("description",
			new IKAnalyzer());
	Query query = parser.parse(str);
	lis=a.doSearch(query);
	if(lis.size()==0){
		out.print("没有查询到结果");
	}
	else{	
		
	}

} catch (Exception e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}


int i=0;
for(Crawl crawl: lis){
	i=i+1;
	//out.print(crawl.getDescription()+"<br>"+"<br>");
}

%>

<script type="text/javascript">


$(function(){
    var Count = "<%=i %>";//记录条数
    var tmp = "<%=test %>";
    var PageSize=5;//设置每页示数目
    var PageCount=Math.ceil(Count/PageSize);//计算总页数
    var currentPage =1;//当前页，默认为1。
    //造个简单的分页按钮
    for(var i=1;i<=PageCount;i++){
    	if(PageCount==1){
    	}//如果页数为1的话，那么我们就是不分页

    	else{
    	var pageN='<li style=\"font-size:30px\"><a href="?name='+tmp+'&a='+i+'">'+i+'</a></li>';
    	
    	$('.pagination').append(pageN);
    }

    }
    
	//显示默认页（第一页）

});  
</script>








<%

String d =request.getParameter("a");    //分页数的话改的要比较多一点哦
//out.print(d+"<br>");
int b=0;
int k=0;
if(i!=0&&d==null){
	for(Crawl crawl: lis){
		if(5>k&&k>=0){
			out.print("<h3><p class=\"text-center\"><a href=\""+crawl.getUrl()+"\">"+crawl.getAbs()+"</a></p></h3>"); 
			out.print("<p class=\"text-center\">"+crawl.getDescription()+"<br>");   //如果选择分页的话，这个数据会改很多
			out.print("<br>");
		}
		k=k+1;
	}
	
	
}
else{
if(d!=null){
int c=Integer.valueOf(d);
//out.print(c);
for(Crawl crawl: lis){
	if(c*5>b&&b>=(c-1)*5){
		if(crawl.getDescription()==null){
			out.print("");
		}
		else{
			out.print("<h3><p class=\"text-center\"><a href=\""+crawl.getUrl()+"\">"+crawl.getAbs()+"</a></p></h3>"); 
			out.print("<p class=\"text-center\">"+crawl.getDescription()+"<br>"); 
		out.print("<br>");

		}
	}
	b=b+1;	
}
}
}

//原来在这边的话就是要传入俩个参数，第一个的话name=防盗网&&a=

%>


<br/>

<div class="fy">
	<ul class="pagination ">

</ul>
</div>


</body>
</html>
